package com.combetter.changxing.ui.activity;

import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.combetter.changxing.R;
import com.combetter.changxing.bluetooth.FacilityClient2;
import com.combetter.changxing.model.EventMessage;
import com.combetter.changxing.ui.base.BaseActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 类名  ElectronicPipe
 * 作者  tlfx: Sean.guo
 * 日期  2019/4/11 09:01
 */
public class TestAuthActivity extends BaseActivity implements View.OnClickListener {
    private Button btn_dw;
    private TextView tv_logger;

    @Override
    public int setLayout() {
        EventBus.getDefault().register(this);

        return R.layout.activity_test_auth;
    }


    @Override
    public void init() {
        btn_dw = findViewById(R.id.btn_dw);
        btn_dw.setOnClickListener(this);
        tv_logger = findViewById(R.id.tv_logger);
        tv_logger.setMovementMethod(ScrollingMovementMethod.getInstance());

    }

    @Override
    public Class createViewModel() {
        return null;
    }

    @Override
    public void loadData() {

    }

    @Override
    public void onClick(View v) {
        FacilityClient2.getClient().authAgain();
    }

    private void clearLog() {
        tv_logger.setText("");
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getEventData(EventMessage message) {
        switch (message.getType()) {
            // 蓝牙连接成功
            case "authTest":
                tv_logger.setText((String) message.getData());
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }
}
